CURRPATH=$(shell pwd)
COMMON_FLAGS= -I$(CURRPATH)/boost_1_46_0 -Wall -Werror 
CPPFLAGS= -include iBe.h -fpch-preprocess -Winvalid-pch
LDFLAGS= -lsqlite3 -lOSMesa32 -lGLU -lssl

BUILDPATH=build
SRCPATH=src

TARGET_SRCS=$(subst $(SRCPATH)/,,$(wildcard $(SRCPATH)/bin/*.cpp))
TARGET_OBJS=$(patsubst %.cpp,%.o,$(TARGET_SRCS))
TARGET=$(subst .cpp,,$(notdir $(wildcard $(SRCPATH)/bin/*.cpp)))

SRCS=$(subst $(SRCPATH)/,,$(wildcard $(SRCPATH)/*.cpp $(SRCPATH)/*/*.cpp))
SUB_DIRS=$(subst $(SRCPATH)/,,$(shell echo $(SRCPATH)/*/))
OBJS=$(filter-out $(TARGET_OBJS), $(patsubst %.cpp,%.o,$(SRCS)))
GCH=iBe.h

export GCH
export CURRPATH
export BUILDPATH
export COMMON_FLAGS
export CPPFLAGS
export LDFLAGS
export SRCPATH
export OBJS
export TARGET_OBJS
export TARGET

all: debug

%: make.%
	mkdir -p $(BUILDPATH)/$@ $(addprefix $(BUILDPATH)/$@/, $(SUB_DIRS))
	$(MAKE) -C $(BUILDPATH)/$@ -f $(CURRPATH)/make.$@

src-clean:
	rm -f *~ src/*~

%-clean:
	rm -r $(BUILDPATH)/$*/*

clean: src-clean
	rm -r -f build
